﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data.SqlClient;
using System.Data;

namespace HandLab.WpfApp
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        SqlDataAdapter sda;
        DataTable dt;

        public MainWindow()
        {
            InitializeComponent();
            GetData();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            GetData();
        }

        private void GetData()
        {
            //init sqlconnection
            SqlConnectionStringBuilder connbuilder = new SqlConnectionStringBuilder();
            connbuilder.DataSource = "192.168.0.95";
            connbuilder.UserID = "sa";
            connbuilder.Password = "Abcd123";
            connbuilder.InitialCatalog = "AK_NetDrive1";

            //start to make sql query
            SqlConnection conn = new SqlConnection(connbuilder.ConnectionString);
            sda = new SqlDataAdapter("select * from ND_FileInfo", conn);
            SqlCommandBuilder commbuilder = new SqlCommandBuilder(sda);
            sda.UpdateCommand = commbuilder.GetUpdateCommand();
            dt = new DataTable();
            sda.AcceptChangesDuringUpdate = true;
            sda.Fill(dt);
            listView1.ItemsSource = dt.DefaultView;
        }
    }
}
